package com.fr.base.xml;

import com.fr.base.ColumnRow;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.Inter;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.background.GradientBackground;
import com.fr.base.background.ImageBackground;
import com.fr.base.background.IntervalColorBackground;
import com.fr.base.background.PatternBackground;
import com.fr.base.background.TextureBackground;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.FRCoreContext;
import com.fr.base.core.GraphHelper;
import com.fr.chart.marker.AllEqualMarker;
import com.fr.chart.marker.AntiClockLineMarker;
import com.fr.chart.marker.CircleFilledMarker;
import com.fr.chart.marker.CircleMarker;
import com.fr.chart.marker.ClockLineMarker;
import com.fr.chart.marker.CrossMarker;
import com.fr.chart.marker.DiamondFilledMarker;
import com.fr.chart.marker.DiamondMarker;
import com.fr.chart.marker.DowJonesMarker;
import com.fr.chart.marker.Marker;
import com.fr.chart.marker.MinusSignMarker;
import com.fr.chart.marker.NullMarker;
import com.fr.chart.marker.PlusSignMarker;
import com.fr.chart.marker.PointMarker;
import com.fr.chart.marker.RoundFilledMarker;
import com.fr.chart.marker.RoundMarker;
import com.fr.chart.marker.SquareFilledMarker;
import com.fr.chart.marker.SquareMarker;
import com.fr.chart.marker.StarMarker;
import com.fr.chart.marker.TriangleFilledMarker;
import com.fr.chart.marker.TriangleMarker;
import com.fr.chart.marker.XMarker;
import com.fr.util.Utils;
import java.awt.Color;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.Toolkit;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.image.BufferedImage;
import java.awt.image.MemoryImageSource;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.StringWriter;
import java.security.MessageDigest;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;

public class BaseXMLUtils
{
  private static final String[][] decodeArray = { { "&amp;", "&lt;", "&gt;", "&apos;", "&quot;" }, { "&", "<", ">", "'", "\"" } };

  public static Object readXMLFile(Reader paramReader, XMLFileReader paramXMLFileReader)
    throws Exception
  {
    XMLableReader localXMLableReader = XMLableReader.createXMLableReader(paramReader);
    if (localXMLableReader != null)
    {
      String str = localXMLableReader.getTagName();
      if (str == null)
        throw new Exception("Error template file.");
      return paramXMLFileReader.readFileContent(localXMLableReader);
    }
    return null;
  }

  public static Object readXMLFile(InputStream paramInputStream, XMLFileReader paramXMLFileReader)
    throws Exception
  {
    return readXMLFile(new InputStreamReader(paramInputStream, "UTF-8"), paramXMLFileReader);
  }

  public static void writeXMLFile(OutputStream paramOutputStream, XMLWriter paramXMLWriter)
  {
    XMLPrintWriter localXMLPrintWriter = XMLPrintWriter.create(paramOutputStream);
    paramXMLWriter.writeXML(localXMLPrintWriter);
    localXMLPrintWriter.flush();
    localXMLPrintWriter.close();
  }

  public static Background readBackground(XMLableReader paramXMLableReader)
  {
    String str;
    Object localObject2;
    Object localObject1 = null;
    if ((str = paramXMLableReader.getAttr("name")) != null)
    {
      if (str.equals("NullBackground"))
        return null;
      if (str.equals("ColorBackground"))
        localObject1 = ColorBackground.getInstance();
      else if (str.equals("GradientBackground"))
        localObject1 = new GradientBackground();
      else if (str.equals("TextureBackground"))
        localObject1 = new TextureBackground();
      else if (str.equals("PatternBackground"))
        localObject1 = new PatternBackground();
      else if (str.equals("ImageBackground"))
        localObject1 = new ImageBackground();
      else if (str.equals("BGBackground"))
        localObject1 = new IntervalColorBackground();
    }
    if (localObject1 == null)
      if ((str = paramXMLableReader.getAttr("class")) != null)
      {
        if (str.equals("null"))
          return null;
        str = Utils.replaceAllString(str, "com.fr.report.background", "com.fr.base.background");
        try
        {
          localObject1 = (Background)FRCoreContext.classForName(str).newInstance();
        }
        catch (Exception localException)
        {
          FRContext.getLogger().log(Level.SEVERE, "Load class with name: " + str, localException);
        }
      }
    if (localObject1 == null)
      return localObject1;
    if (localObject1 instanceof ColorBackground)
    {
      localObject2 = null;
      if ((str = paramXMLableReader.getAttr("color")) != null)
        localObject2 = ColorBackground.getInstance(new Color(Integer.parseInt(str), true));
      localObject1 = localObject2;
    }
    else if (localObject1 instanceof GradientBackground)
    {
      if ((str = paramXMLableReader.getAttr("color1")) != null)
        ((GradientBackground)localObject1).setColor1(new Color(Integer.parseInt(str), true));
      if ((str = paramXMLableReader.getAttr("color2")) != null)
        ((GradientBackground)localObject1).setColor2(new Color(Integer.parseInt(str), true));
      if ((str = paramXMLableReader.getAttr("direction")) != null)
        ((GradientBackground)localObject1).setDirection(Integer.parseInt(str));
      if ((str = paramXMLableReader.getAttr("useCell")) != null)
      {
        ((GradientBackground)localObject1).setUseCell(Boolean.valueOf(str).booleanValue());
        if (Boolean.valueOf(str).booleanValue())
          return localObject1;
      }
      if ((str = paramXMLableReader.getAttr("begin")) != null)
        ((GradientBackground)localObject1).setBeginPlace(Float.parseFloat(str));
      if ((str = paramXMLableReader.getAttr("finish")) != null)
        ((GradientBackground)localObject1).setFinishPlace(Float.parseFloat(str));
      if ((str = paramXMLableReader.getAttr("cyclic")) != null)
        ((GradientBackground)localObject1).setCyclic(Boolean.valueOf(str).booleanValue());
    }
    else if (localObject1 instanceof TextureBackground)
    {
      localObject2 = (TextureBackground)localObject1;
      paramXMLableReader.readXMLObject(new XMLReadable((TextureBackground)localObject2)
      {
        private final TextureBackground val$textureBackground;

        public void readXML(XMLableReader paramXMLableReader)
        {
          if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("TexturePaint")))
            this.val$textureBackground.setTexturePaint(BaseXMLUtils.readTexturePaint(paramXMLableReader));
        }
      });
    }
    else if (localObject1 instanceof PatternBackground)
    {
      localObject2 = (PatternBackground)localObject1;
      if ((str = paramXMLableReader.getAttr("patternIndex")) != null)
        ((PatternBackground)localObject2).setPatternIndex(Integer.parseInt(str));
      if ((str = paramXMLableReader.getAttr("foreground")) != null)
        ((PatternBackground)localObject2).setForeground(new Color(Integer.parseInt(str), true));
      if ((str = paramXMLableReader.getAttr("background")) != null)
        ((PatternBackground)localObject2).setBackground(new Color(Integer.parseInt(str), true));
    }
    else if (localObject1 instanceof ImageBackground)
    {
      localObject2 = (ImageBackground)localObject1;
      if ((str = paramXMLableReader.getAttr("specifiedImageWidth")) != null)
        ((ImageBackground)localObject2).setSpecifiedImageWidth(Double.parseDouble(str));
      if ((str = paramXMLableReader.getAttr("specifiedImageHeight")) != null)
        ((ImageBackground)localObject2).setSpecifiedImageHeight(Double.parseDouble(str));
      if ((str = paramXMLableReader.getAttr("layout")) != null)
        ((ImageBackground)localObject2).setLayout(Integer.parseInt(str));
      paramXMLableReader.readXMLObject(new XMLReadable((ImageBackground)localObject2)
      {
        private final ImageBackground val$imageBackground;

        public void readXML(XMLableReader paramXMLableReader)
        {
          if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("Image")))
            this.val$imageBackground.setImage(BaseXMLUtils.readImage(paramXMLableReader));
        }
      });
    }
    return ((Background)(Background)localObject1);
  }

  public static String writeXMLableAsString(XMLWriter paramXMLWriter)
  {
    StringWriter localStringWriter = new StringWriter();
    XMLPrintWriter localXMLPrintWriter = XMLPrintWriter.create(localStringWriter, false);
    localXMLPrintWriter.startTAG("R");
    if (paramXMLWriter != null)
      paramXMLWriter.writeXML(localXMLPrintWriter);
    localXMLPrintWriter.end();
    localXMLPrintWriter.flush();
    localXMLPrintWriter.close();
    return localStringWriter.getBuffer().toString();
  }

  public static XMLReadable readStringAsXMLable(String paramString, XMLReadable paramXMLReadable)
  {
    XMLableReader localXMLableReader;
    try
    {
      localXMLableReader = XMLableReader.createXMLableReader(paramString);
      localXMLableReader.readXMLObject(paramXMLReadable);
    }
    catch (XMLStreamException localXMLStreamException)
    {
      FRContext.getLogger().log(Level.WARNING, localXMLStreamException.getMessage(), localXMLStreamException);
    }
    return paramXMLReadable;
  }

  public static void writeColumnRow(XMLPrintWriter paramXMLPrintWriter, ColumnRow paramColumnRow)
  {
    paramXMLPrintWriter.startTAG("ColumnRow").attr("column", paramColumnRow.getColumn()).attr("row", paramColumnRow.getRow()).end();
  }

  public static void writeBackground(XMLPrintWriter paramXMLPrintWriter, Background paramBackground)
  {
    Object localObject;
    paramXMLPrintWriter.startTAG("Background");
    if (paramBackground == null)
    {
      paramXMLPrintWriter.attr("name", "NullBackground").end();
      return;
    }
    if (paramBackground instanceof ColorBackground)
    {
      paramXMLPrintWriter.attr("name", "ColorBackground");
      localObject = (ColorBackground)paramBackground;
      if (((ColorBackground)localObject).getColor() != null)
        paramXMLPrintWriter.attr("color", ((ColorBackground)localObject).getColor().getRGB());
    }
    else if (paramBackground instanceof GradientBackground)
    {
      paramXMLPrintWriter.attr("name", "GradientBackground");
      localObject = (GradientBackground)paramBackground;
      if (((GradientBackground)localObject).getColor1() != null)
        paramXMLPrintWriter.attr("color1", ((GradientBackground)localObject).getColor1().getRGB());
      if (((GradientBackground)localObject).getColor2() != null)
        paramXMLPrintWriter.attr("color2", ((GradientBackground)localObject).getColor2().getRGB());
      paramXMLPrintWriter.attr("direction", ((GradientBackground)localObject).getDirection()).attr("useCell", ((GradientBackground)localObject).isUseCell()).attr("begin", ((GradientBackground)localObject).getBeginPlace()).attr("finish", ((GradientBackground)localObject).getFinishPlace()).attr("cyclic", ((GradientBackground)localObject).isCyclic());
    }
    else if (paramBackground instanceof TextureBackground)
    {
      paramXMLPrintWriter.attr("name", "TextureBackground");
      localObject = (TextureBackground)paramBackground;
      if (((TextureBackground)localObject).getTexturePaint() != null)
        writeTexturePaint(paramXMLPrintWriter, ((TextureBackground)localObject).getTexturePaint());
    }
    else if (paramBackground instanceof PatternBackground)
    {
      paramXMLPrintWriter.attr("name", "PatternBackground");
      localObject = (PatternBackground)paramBackground;
      paramXMLPrintWriter.attr("patternIndex", ((PatternBackground)localObject).getPatternIndex());
      if (((PatternBackground)localObject).getForeground() != null)
        paramXMLPrintWriter.attr("foreground", ((PatternBackground)localObject).getForeground().getRGB());
      if (((PatternBackground)localObject).getBackground() != null)
        paramXMLPrintWriter.attr("background", ((PatternBackground)localObject).getBackground().getRGB());
    }
    else if (paramBackground instanceof ImageBackground)
    {
      paramXMLPrintWriter.attr("name", "ImageBackground");
      localObject = (ImageBackground)paramBackground;
      paramXMLPrintWriter.attr("specifiedImageWidth", ((ImageBackground)localObject).getSpecifiedImageWidth()).attr("specifiedImageHeight", ((ImageBackground)localObject).getSpecifiedImageHeight()).attr("layout", ((ImageBackground)localObject).getLayout());
      if (((ImageBackground)localObject).getImage() != null)
        writeImage(paramXMLPrintWriter, ((ImageBackground)localObject).getImage());
    }
    else
    {
      paramXMLPrintWriter.attr("class", paramBackground.getClass().getName());
    }
    paramXMLPrintWriter.end();
  }

  public static void writeMarker(XMLPrintWriter paramXMLPrintWriter, Marker paramMarker)
  {
    paramXMLPrintWriter.startTAG("Marker");
    if (paramMarker == null)
      paramXMLPrintWriter.attr("class", "null");
    else
      paramXMLPrintWriter.attr("class", paramMarker.getClass().getName());
    paramXMLPrintWriter.attr("size", paramMarker.getSize());
    if (paramMarker.getColor() != null)
      paramXMLPrintWriter.attr("color", paramMarker.getColor().getRGB());
    paramXMLPrintWriter.end();
  }

  public static Marker readMarker(XMLableReader paramXMLableReader)
  {
    String str;
    Object localObject = null;
    if ((str = paramXMLableReader.getAttr("class")) != null)
    {
      if (str.equals("null"))
        return null;
      if (str.endsWith(".AllEqualMarker"))
        localObject = new AllEqualMarker();
      else if (str.endsWith(".AntiClockLineMarkerAnti"))
        localObject = new AntiClockLineMarker();
      else if (str.endsWith(".CircleMarker"))
        localObject = new CircleMarker();
      else if (str.endsWith(".CircleFilledMarker"))
        localObject = new CircleFilledMarker();
      else if (str.endsWith(".ClockLineMarker"))
        localObject = new ClockLineMarker();
      else if (str.endsWith(".CrossMarker"))
        localObject = new CrossMarker();
      else if (str.endsWith(".DiamondFilledMarker"))
        localObject = new DiamondFilledMarker();
      else if (str.endsWith(".DiamondMarker"))
        localObject = new DiamondMarker();
      else if (str.endsWith(".DowJonesMarker"))
        localObject = new DowJonesMarker();
      else if (str.endsWith(".MinusSignMarker"))
        localObject = new MinusSignMarker();
      else if (str.endsWith(".NullMarker"))
        localObject = new NullMarker();
      else if (str.endsWith(".PlusSignMarker"))
        localObject = new PlusSignMarker();
      else if (str.endsWith(".PointMarker"))
        localObject = new PointMarker();
      else if (str.endsWith(".RoundFilledMarker"))
        localObject = new RoundFilledMarker();
      else if (str.endsWith(".RoundMarker"))
        localObject = new RoundMarker();
      else if (str.endsWith(".SquareFilledMarker"))
        localObject = new SquareFilledMarker();
      else if (str.endsWith(".SquareMarker"))
        localObject = new SquareMarker();
      else if (str.endsWith(".StarMarker"))
        localObject = new StarMarker();
      else if (str.endsWith(".TriangleFilledMarker"))
        localObject = new TriangleFilledMarker();
      else if (str.endsWith(".TriangleMarker"))
        localObject = new TriangleMarker();
      else if (str.endsWith(".XMarker"))
        localObject = new XMarker();
    }
    if (localObject != null)
    {
      if ((str = paramXMLableReader.getAttr("size")) != null)
        ((Marker)localObject).setSize(Double.valueOf(str).doubleValue());
      if ((str = paramXMLableReader.getAttr("color")) != null)
        ((Marker)localObject).setColor(new Color(Integer.parseInt(str), true));
    }
    return ((Marker)localObject);
  }

  public static FRFont readFRFont(XMLableReader paramXMLableReader)
  {
    String str;
    Object localObject = "";
    int i = 0;
    int j = 0;
    if ((str = paramXMLableReader.getAttr("name")) != null)
      localObject = str;
    if ((str = paramXMLableReader.getAttr("style")) != null)
      i = Integer.parseInt(str);
    if ((str = paramXMLableReader.getAttr("size")) != null)
      j = Integer.parseInt(str);
    FRFont localFRFont = FRFont.getInstance((String)localObject, i, j);
    if ((str = paramXMLableReader.getAttr("foreground")) != null)
      localFRFont = localFRFont.applyForeground(new Color(Integer.parseInt(str), true));
    if ((str = paramXMLableReader.getAttr("underline")) != null)
      localFRFont = localFRFont.applyUnderline(Integer.parseInt(str));
    if ((str = paramXMLableReader.getAttr("isStrikethrough")) != null)
      localFRFont = localFRFont.applyStrikethrough(Boolean.valueOf(str).booleanValue());
    if ((str = paramXMLableReader.getAttr("isShadow")) != null)
      localFRFont = localFRFont.applyShadow(Boolean.valueOf(str).booleanValue());
    if ((str = paramXMLableReader.getAttr("isSuperscript")) != null)
      localFRFont = localFRFont.applySuperscript(Boolean.valueOf(str).booleanValue());
    if ((str = paramXMLableReader.getAttr("isSubscript")) != null)
      localFRFont = localFRFont.applySubscript(Boolean.valueOf(str).booleanValue());
    return ((FRFont)localFRFont);
  }

  public static void writeFRFont(XMLPrintWriter paramXMLPrintWriter, FRFont paramFRFont)
  {
    paramXMLPrintWriter.startTAG("FRFont").attr("name", paramFRFont.getName()).attr("style", paramFRFont.getStyle()).attr("size", paramFRFont.getSize());
    if ((paramFRFont.getForeground() != null) && (!(paramFRFont.getForeground().equals(Color.black))))
      paramXMLPrintWriter.attr("foreground", paramFRFont.getForeground().getRGB());
    if (paramFRFont.getUnderline() != 0)
      paramXMLPrintWriter.attr("underline", paramFRFont.getUnderline());
    if (paramFRFont.isStrikethrough())
      paramXMLPrintWriter.attr("isStrikethrough", paramFRFont.isStrikethrough());
    if (paramFRFont.isShadow())
      paramXMLPrintWriter.attr("isShadow", paramFRFont.isShadow());
    if (paramFRFont.isSuperscript())
      paramXMLPrintWriter.attr("isSuperscript", paramFRFont.isSuperscript());
    if (paramFRFont.isSubscript())
      paramXMLPrintWriter.attr("isSubscript", paramFRFont.isSubscript());
    paramXMLPrintWriter.end();
  }

  public static boolean isFRFontTagName(String paramString)
  {
    if (paramString == null)
      return false;
    return ((paramString.equals("CellFont")) || (paramString.equals("ReportFont")) || (paramString.equals("FRFont")));
  }

  public static void writeTexturePaint(XMLPrintWriter paramXMLPrintWriter, TexturePaint paramTexturePaint)
  {
    paramXMLPrintWriter.startTAG("TexturePaint");
    Rectangle2D localRectangle2D = paramTexturePaint.getAnchorRect();
    paramXMLPrintWriter.startTAG("Rectangle2D").attr("x", localRectangle2D.getX()).attr("y", localRectangle2D.getY()).attr("width", localRectangle2D.getWidth()).attr("height", localRectangle2D.getHeight()).end();
    writeImage(paramXMLPrintWriter, paramTexturePaint.getImage());
    paramXMLPrintWriter.end();
  }

  public static TexturePaint readTexturePaint(XMLableReader paramXMLableReader)
  {
    3 local3 = new XMLObject(new Object[2])
    {
      public void readXML(XMLableReader paramXMLableReader)
      {
        if (paramXMLableReader.isChildNode())
        {
          String str2 = paramXMLableReader.getTagName();
          if (str2.equals("Rectangle2D"))
          {
            String str1;
            double d1 = 0.0D;
            double d2 = 0.0D;
            double d3 = 0.0D;
            double d4 = 0.0D;
            if ((str1 = paramXMLableReader.getAttr("x")) != null)
              d1 = Double.parseDouble(str1);
            if ((str1 = paramXMLableReader.getAttr("y")) != null)
              d2 = Double.parseDouble(str1);
            if ((str1 = paramXMLableReader.getAttr("width")) != null)
              d3 = Double.parseDouble(str1);
            if ((str1 = paramXMLableReader.getAttr("height")) != null)
              d4 = Double.parseDouble(str1);
            ((Object[])this.obj)[0] = new Rectangle2D.Double(d1, d2, d3, d4);
          }
          else if (str2.equals("Image"))
          {
            ((Object[])this.obj)[1] = GraphHelper.createBufferedImageFromImage(BaseXMLUtils.readImage(paramXMLableReader));
          }
        }
      }
    };
    paramXMLableReader.readXMLObject(local3);
    return new TexturePaint((BufferedImage)((Object[])local3.getObject())[1], (Rectangle2D)((Object[])local3.getObject())[0]);
  }

  public static Rectangle readRectangle(String paramString)
  {
    Rectangle localRectangle = new Rectangle();
    String[] arrayOfString = Utils.splitString(paramString, ",");
    if ((arrayOfString != null) && (arrayOfString.length == 4))
    {
      localRectangle.x = Integer.parseInt(arrayOfString[0]);
      localRectangle.y = Integer.parseInt(arrayOfString[1]);
      localRectangle.width = Integer.parseInt(arrayOfString[2]);
      localRectangle.height = Integer.parseInt(arrayOfString[3]);
    }
    return localRectangle;
  }

  public static String getRectangleText(Rectangle paramRectangle)
  {
    return paramRectangle.x + "," + paramRectangle.y + "," + paramRectangle.width + "," + paramRectangle.height;
  }

  public static String xmlAttrEncode(String paramString)
  {
    return BaseCoreUtils.encodeString(paramString, decodeArray);
  }

  public static String generateTextKey(String paramString)
  {
    byte[] arrayOfByte1;
    try
    {
      arrayOfByte1 = paramString.getBytes("UTF-8");
      StringBuffer localStringBuffer = new StringBuffer();
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      localMessageDigest.update(arrayOfByte1);
      byte[] arrayOfByte2 = localMessageDigest.digest();
      for (int j = 2; j <= 5; ++j)
      {
        i = arrayOfByte2[j] & 0xFF;
        localStringBuffer.append((char)(i % 25 + 65));
      }
      localStringBuffer.append("-");
      for (j = 7; j <= 11; ++j)
      {
        i = arrayOfByte2[j] & 0xFF;
        if (j == 9)
          localStringBuffer.append(Integer.toHexString(i % 16));
        else
          localStringBuffer.append(i % 10);
      }
      localStringBuffer.append("-");
      int i = arrayOfByte2[15] & 0xFF;
      localStringBuffer.append((char)(i % 25 + 65));
      for (j = 14; j >= 12; --j)
      {
        i = arrayOfByte2[j] & 0xFF;
        localStringBuffer.append(i % 10);
      }
      for (j = 6; j >= 3; --j)
      {
        i = arrayOfByte2[j] & 0xFF;
        localStringBuffer.append(Integer.toHexString(i % 16));
      }
      localStringBuffer.append("-");
      for (j = 4; j >= 1; --j)
      {
        i = arrayOfByte2[j] & 0xFF;
        localStringBuffer.append(i % 10);
      }
      return localStringBuffer.toString().toUpperCase();
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return "";
  }

  public static void writeImage(XMLPrintWriter paramXMLPrintWriter, Image paramImage)
  {
    if (paramImage == null)
      return;
    GraphHelper.waitForImage(paramImage);
    int i = paramImage.getWidth(null);
    int j = paramImage.getHeight(null);
    paramXMLPrintWriter.startTAG("Image").attr("width", i).attr("height", j);
    writeByteArray(paramXMLPrintWriter, image2Bytes(paramImage));
    paramXMLPrintWriter.end();
  }

  public static byte[] image2Bytes(Image paramImage)
  {
    int[] arrayOfInt = Utils.grabImagePixelsArray(paramImage, paramImage.getWidth(null), paramImage.getHeight(null));
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    for (int i = 0; i < arrayOfInt.length; ++i)
    {
      int j = arrayOfInt[i];
      localByteArrayOutputStream.write((byte)((j & 0xFF0000) >> 16));
      localByteArrayOutputStream.write((byte)((j & 0xFF00) >> 8));
      localByteArrayOutputStream.write((byte)(j & 0xFF));
      localByteArrayOutputStream.write((byte)((j & 0xFF000000) >> 24));
    }
    return localByteArrayOutputStream.toByteArray();
  }

  public static Image readImage(XMLableReader paramXMLableReader)
  {
    String str;
    int i = 0;
    int j = 0;
    if ((str = paramXMLableReader.getAttr("width")) != null)
      i = Integer.parseInt(str);
    if ((str = paramXMLableReader.getAttr("height")) != null)
      j = Integer.parseInt(str);
    byte[] arrayOfByte = readByteArray(paramXMLableReader);
    if (i * j * 4 != arrayOfByte.length)
      throw new RuntimeException(BaseCoreUtils.join(new String[] { Inter.getLocText("EX-Image_stored_is_broken"), ":", String.valueOf(i), "*", String.valueOf(j), "*4=", String.valueOf(i * j * 4), "!=", String.valueOf(arrayOfByte.length) }));
    int[] arrayOfInt = new int[i * j];
    int k = 0;
    int l = 0;
    for (int i1 = 0; i1 < j; ++i1)
      for (int i2 = 0; i2 < i; ++i2)
      {
        int i3 = arrayOfByte[(k++)] & 0xFF;
        int i4 = arrayOfByte[(k++)] & 0xFF;
        int i5 = arrayOfByte[(k++)] & 0xFF;
        int i6 = arrayOfByte[(k++)] & 0xFF;
        arrayOfInt[(l++)] = (i6 << 24 | i3 << 16 | i4 << 8 | i5);
      }
    return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(i, j, arrayOfInt, 0, i));
  }

  public static byte[] encodeImage(Image paramImage)
  {
    GraphHelper.waitForImage(paramImage);
    int i = paramImage.getWidth(null);
    int j = paramImage.getHeight(null);
    int[] arrayOfInt = Utils.grabImagePixelsArray(paramImage, i, j);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    for (int k = 0; k < arrayOfInt.length; ++k)
    {
      int l = arrayOfInt[k];
      localByteArrayOutputStream.write((byte)((l & 0xFF0000) >> 16));
      localByteArrayOutputStream.write((byte)((l & 0xFF00) >> 8));
      localByteArrayOutputStream.write((byte)(l & 0xFF));
      localByteArrayOutputStream.write((byte)((l & 0xFF000000) >> 24));
    }
    return localByteArrayOutputStream.toByteArray();
  }

  public static Image decodeImage(int paramInt1, int paramInt2, byte[] paramArrayOfByte)
  {
    int[] arrayOfInt = new int[paramInt1 * paramInt2];
    int i = 0;
    int j = 0;
    for (int k = 0; k < paramInt2; ++k)
      for (int l = 0; l < paramInt1; ++l)
      {
        int i1 = paramArrayOfByte[(i++)] & 0xFF;
        int i2 = paramArrayOfByte[(i++)] & 0xFF;
        int i3 = paramArrayOfByte[(i++)] & 0xFF;
        int i4 = paramArrayOfByte[(i++)] & 0xFF;
        arrayOfInt[(j++)] = (i4 << 24 | i1 << 16 | i2 << 8 | i3);
      }
    return Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(paramInt1, paramInt2, arrayOfInt, 0, paramInt1));
  }

  public static void writeByteArray(XMLPrintWriter paramXMLPrintWriter, byte[] paramArrayOfByte)
  {
    paramXMLPrintWriter.textNode(XMLEncodeUtils.encodeBytesAsString(paramArrayOfByte));
  }

  public static byte[] readByteArray(XMLableReader paramXMLableReader)
  {
    return XMLEncodeUtils.decodeStringAsBytes(paramXMLableReader.getElementValue());
  }
}